package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bussiness.domain.SysBusinessPolicy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SysBusinessPortfolio;
import com.ruoyi.bussiness.service.ISysBusinessPortfolioService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品集Controller
 *
 * @author ruoyi
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/bussiness/portfolio")
public class SysBusinessPortfolioController extends BaseController
{
    @Autowired
    private ISysBusinessPortfolioService sysBusinessPortfolioService;

    /**
     * 查询作品集列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessPortfolio sysBusinessPortfolio)
    {
        startPage();
        List<SysBusinessPortfolio> list = sysBusinessPortfolioService.selectSysBusinessPortfolioList(sysBusinessPortfolio);
        return getDataTable(list);
    }

    /**
     * 导出作品集列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:export')")
    @Log(title = "作品集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessPortfolio sysBusinessPortfolio)
    {
        List<SysBusinessPortfolio> list = sysBusinessPortfolioService.selectSysBusinessPortfolioList(sysBusinessPortfolio);
        ExcelUtil<SysBusinessPortfolio> util = new ExcelUtil<SysBusinessPortfolio>(SysBusinessPortfolio.class);
        util.exportExcel(response, list, "作品集数据");
    }

    /**
     * 获取作品集详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysBusinessPortfolioService.selectSysBusinessPortfolioById(id));
    }

    /**
     * 新增作品集
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:add')")
    @Log(title = "作品集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessPortfolio sysBusinessPortfolio)
    {
        return toAjax(sysBusinessPortfolioService.insertSysBusinessPortfolio(sysBusinessPortfolio));
    }

    /**
     * 修改作品集
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:edit')")
    @Log(title = "作品集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessPortfolio sysBusinessPortfolio)
    {
        return toAjax(sysBusinessPortfolioService.updateSysBusinessPortfolio(sysBusinessPortfolio));
    }

    /**
     * 删除作品集
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:remove')")
    @Log(title = "作品集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBusinessPortfolioService.deleteSysBusinessPortfolioByIds(ids));
    }

    /**
     * 上移下移政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:edit')")
    @Log(title = "作品集", businessType = BusinessType.UPDATE)
    @PutMapping("/moveUpOrDown")
    public AjaxResult moveUpOrDown(@RequestBody SysBusinessPortfolio entity)
    {
        return sysBusinessPortfolioService.moveUpOrDown(entity);
    }

    /**
     * 置顶 置底政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:portfolio:edit')")
    @Log(title = "作品集", businessType = BusinessType.UPDATE)
    @PutMapping("/pinToTopOrEnd")
    public AjaxResult pinToTopOrEnd(@RequestBody SysBusinessPortfolio entity)
    {
        return sysBusinessPortfolioService.pinToTopOrEnd(entity);
    }
}
